<template>
  <div class="app-container">
    <div class="select-time">
      <el-form :inline="true">
        <el-form-item label="选择时间">
          <el-date-picker
            v-model="date_value"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >

      <el-table-column align="left" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="110" align="left">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="性别" width="110" align="left">
        <template slot-scope="scope">
          {{ scope.row.sex }}
        </template>
      </el-table-column>
      <el-table-column label="Email" width="260" align="left">
        <template slot-scope="scope">
          {{ scope.row.email }}
        </template>
      </el-table-column>
      <el-table-column label="登记时间" width="300" align="left">
        <template slot-scope="scope">
          {{ scope.row.captured_time }}
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="是否警告" width="110" align="left">
        <template slot-scope="scope">
          <el-tag :type="scope.row.mask_warning | statusFilter">{{ scope.row.mask_warning }}</el-tag>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getNoMaskInfo } from '@/api/nomask'
export default {
  filters: {
    statusFilter(mask_warning) {
      // console.log(mask_warning)
      // var status = 'success'
      // if (no_mask_count > 6) {
      //   status = 'danger'
      // }
      // if (no_mask_count > 3 && no_mask_count < 7) {
      //   status = 'warning'
      // }
      const statusMap = {
        Yes: 'danger',
        No: 'success'
      }
      console.log('res is ' + statusMap[status])
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      date_value: ''
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 测试数据需要使用打log的形式
    // 从后台返回数据
    fetchData() {
      debugger
      this.listLoading = true
      console.log(getNoMaskInfo())
      // 调用API访问数据
      getNoMaskInfo().then(response => {
        console.log('从后台搬运数据成功')
        this.list = response.data.items
        this.listLoading = false
      })
    },
    onSubmit() {
      console.log(this.date_value)
    }
  }
}
</script>
